package water_ruler_threads;

import com.zhejiangzhengyuan.municipal_common.utils.waterRuler.ByteAndStringUtils;
import lombok.extern.slf4j.Slf4j;

import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

@Slf4j
public class SendDataThread implements Runnable {

  private Socket socket;

  private byte[] bytes;

  SendDataThread(Socket socket, byte[] bytes) {
    this.socket = socket;
    this.bytes = bytes;
  }

  public void run() {
    if (socket == null && bytes == null) {
      return;
    }
    DataOutputStream out;
    try {
      String toHex2 = ByteAndStringUtils.byteToHex(bytes);
      log.info("SendDataThread >>>>第二次握手数据:<<<<:{}", toHex2);
      // 向客户端发送信息的DataOutputStream
      out = new DataOutputStream(socket.getOutputStream());
      // 把服务器端的输入发给客户端
      out.write(bytes);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
